package com.gzx.spring.db.controller;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
import com.gzx.risk.core.pojo.CommonResult;
import com.gzx.risk.core.pojo.OrderInfo;
import com.gzx.risk.core.pojo.UserInfo;
import com.gzx.risk.core.tags.CommonLog;
import com.gzx.spring.db.service.PhoneProductOrderService;
import com.gzx.spring.db.service.PhoneUserService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "phone")
@RestController
@Validated
@RequestMapping("/api/phone")
@Slf4j
public class PhoneController {
	@Resource
	private PhoneUserService phoneUserService;
	@Resource
	private PhoneProductOrderService phoneProductOrderService;

	@Operation(summary = "查询用户")
	@CommonLog("查询用户")
	@PostMapping("/user/get")
	public CommonResult<String> getUser(@RequestParam(name = "uid", defaultValue = "26") Long uid) {
		UserInfo user = phoneUserService.getUser(uid);
		log.info("id:{},name:{},phone:{},idLastDate:{},sex:{}", user.getId(), user.getName(), user.getPhone(),
				user.getIdLastdate(), user.getSex());
		return CommonResult.ok();
	}

	@Operation(summary = "查询订单")
	@CommonLog("查询订单")
	@PostMapping("/order/get")
	public CommonResult<String> getOrder(@RequestParam(name = "oid", defaultValue = "16") Long oid) {
		OrderInfo order = phoneProductOrderService.getOrder(oid);
		log.info("ordercode:{},phone:{}", order.getOrdercode(), order.getPhone());
		return CommonResult.ok();
	}

	@Operation(summary = "状态查询订单")
	@CommonLog("状态查询订单")
	@PostMapping("/order/getByStatus")
	public CommonResult<String> getOrdersByStatus(@RequestParam(name = "status", defaultValue = "1") int status) {
		List<OrderInfo> orders = phoneProductOrderService.getOrdersByStatus(Lists.newArrayList(1));
		log.info("orders:{}", orders.size());
		for (OrderInfo order : orders) {
			log.info("id:{},ordercode:{},status:{}", order.getId(), order.getOrdercode(), order.getStatus());
		}
		return CommonResult.ok();
	}
}
